﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GUI_Client_WCF
{
    public partial class GUILogin : Form
    {
        private static GUILogin instance;
        private ServiceReference.IService reference;
        public static ServiceReference.Customer Customer { get; private set; }
        
        private GUILogin()
        {
            InitializeComponent();
            reference = new ServiceReference.ServiceClient();
        }

        public static GUILogin Instance
        {
            get
            {
                if (instance == null)
                    instance = new GUILogin();

                return instance;
            }
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            ServiceReference.Customer cust = reference.CheckLoginCredentials(txtUsername.Text, txtPassword.Text);
            if (cust != null)
            {
                Customer = cust;

                GUIMain main = GUIMain.Instance;
                main.Show();

                this.Hide();
                txtUsername.Clear();
                txtPassword.Clear();
            }
            else
                MessageBox.Show("Login credentials are wrong");
        }
    }
}
